﻿@{
	ViewBag.Title = "账户管理";
}
<link href="@Url.Content("~/Content/themes/base/validationEngine.jquery.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery.validationEngine.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validationEngine-ch.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/themes/base/jquery-mytabs.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery.mytabs.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $("form#Personinfo,form#changedPassword").validationEngine();
        $("form#Personinfo input").attr("disabled", "disabled");
        $(".datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            yearRange: '1949:2010',
            dateFormat: 'yy-mm-dd',
            dayNames: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
            dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
            monthNamesShort: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二']
        });

        $("#updatePersonInfo").button().click(function () {
            if ($("form#Personinfo").validationEngine("validate")) {
                startProcess($("#personInfoMessage"));
                $.post(
					"/User/ajaxUpdatePersonInfo",
					$("#Personinfo").serialize(),
					function (data) {
					    endProcess($("#personInfoMessage"), data.Message, data.State);
					    $("form#Personinfo input").attr("disabled", "disabled");
					    $("#updatePersonInfo").hide();
					    $("#editPersonInfo").show();
					}
				);

            }
            return false;
        }).hide();
        $("#editPersonInfo").button().click(function () {
            $("form#Personinfo input").removeAttr("disabled");
            $(this).hide();
            $("#updatePersonInfo").show();
            return false;
        });
        //
        $("#submit").button().click(function () {
            if ($("form#changedPassword").validationEngine('validate')) {
                startProcess($("#changePasswordMessage"));
                $.post(
					"/Account/ChangePassword",
					$("form#changedPassword").serialize(),
					function (data) {
					    endProcess($("#changePasswordMessage"), data.Message, data.State);
					}
				);
            }
            return false;
        });
        $("#gotoedit").button().click(function () {
            $("#tabs-0-subpage-1").show();
            $("#tabs-0-subpage-0").hide();
            $("#editPersonInfo").button().click();

        });
        var hasLoaded = false;
        $("#tabs").mytabs({
            show: function (panelid) {
                $("form#Personinfo,form#changedPassword").validationEngine('hide');
                if (panelid == "#tabs-0") {
                    if (hasLoaded == false) {
                        startProcess($("#personInfoMessage"));
                        $("#tabs-0-subpage-1").hide();
                        $("#tabs-0-subpage-0").hide();
                        var date = new Date();
                        $.get(
							"/User/ajaxPersonInfoByUserName",
							{ username: $("#UserName").get(0).value,
							    _: date.getMilliseconds()
							},
							function (data) {
							    if (data.State == "Succeed") {
							        $("#tabs-0-subpage-1").show();
							        $("#tabs-0-subpage-0").hide();
							        $("#Name").get(0).value = data.Data.Name;
							        if (data.Data.Gender == "Male")
							            $("#isMale").get(0).checked = "checked";
							        else
							            $("#isFemale").get(0).checked = "checked";
							        $("#BirthDay").get(0).value = data.Data.BirthDay;
							        $("#TechnicalTitle").get(0).value = data.Data.TechnicalTitle;
							        $("#HighestDegree").get(0).value = data.Data.HighestDegree;
							        $("#Major").get(0).value = data.Data.Major;
							        $("#Occupation").get(0).value = data.Data.Occupation;
							        $("#ajaxMessage").text("");
							        hasLoaded = true;
							    } else {
							        $("#tabs-0-subpage-0").show();
							        $("#tabs-0-subpage-1").hide();
							    }
							    endProcess($("#personInfoMessage"), data.Message, data.State);
							}
						);
                    }
                }
            }
        });

    });
</script>


<div id="tabs">
	<ul>
        <li><a href="#tabs-0">信息维护</a></li>
		<li><a href="#tabs-1">更改密码</a></li>
	</ul>
    <div id="tabs-0">      
		<div id="tabs-0-subpage-0">
            <div id="personinfo-prompt"></div>
            <br />
            <button id="gotoedit">现在录入</button>
        </div>
        <div id="tabs-0-subpage-1">
		    <form action="" id="Personinfo">
			    <input type="hidden" id="UserName" name="UserName" value="@HttpContext.Current.User.Identity.Name" />
			    @Html.Partial("PartialPersonInfo")
		    </form>
		    <p>
			    <button id="updatePersonInfo">确定</button>
			    <button id="editPersonInfo" >编辑</button>
		    </p>	
            <div class="message-holder" id="personInfoMessage"></div>
        </div>
	</div>
	<div id="tabs-1">      
		<form action="" id="changedPassword">
			<div id="changepassword-form">      
				<div class="editor-label">
					<label for="OldPassword">旧密码</label>
				</div>
				<div class="editor-field">
					<input class="validate[required,minSize[6],maxSize[30]" id="OldPassword" name="OldPassword" type="password" />
				</div>

				<div class="editor-label">
					<label for="NewPassword">新密码</label>
				</div>
				<div class="editor-field">
					<input class="validate[required,minSize[6],maxSize[30]" id="NewPassword" name="NewPassword" type="password" />
				</div>

				<div class="editor-label">
					<label for="ConfirmPassword">再次输入新密码</label>

				</div>
				<div class="editor-field">
					<input class="validate[required,minSize[6],maxSize[30],equals[NewPassword]]" id="ConfirmPassword" name="ConfirmPassword" type="password" />
				</div>
				<p>
					<button id="submit">提交</button>
				</p>

                <div class="message-holder" id="changePasswordMessage"></div>
			</div>
		</form>
	</div>
</div>

